﻿namespace ScrumLite.WebUx.Tests
{
    using System;
    using System.Collections.Generic;
    using ScrumLite.Services;
    using ScrumLite.Services.Contracts;
    using System.Linq;
    using System.Globalization;

    public class MockMeasuresService: IMeasuresService
    {

        //Dictionary< projectId,Dictionary< ProcessName,List<Measure> > >
        private Dictionary<string,Dictionary<string,List<Measure>>> Measures;

        private List<string> ProjectUris = new List<string>
        (
            new string[]
            {
                "02036DFC-63D0-46DE-82CF-0E7A7DACCBA4",
                "13C659FB-FA13-4343-BA36-1AF8B48EEE97",
                "96585FB8-2FCD-41AE-9807-1C9C4E76FA20",
                "1D8EFB61-24CF-49D9-BA26-2BC45E45610C",
                "185E58A8-279B-4B8E-9590-3302A88858BF",
                "41E98E4C-681A-4988-8F11-4292C8E868E4",
                "9F30E28E-A9C3-4DFE-AD8E-44C7F22E9A7E",
                "54E3A2E3-DBEB-46B2-8BCC-4AB70A9C746A",
                "A36F736D-5C0C-4DB8-B608-4D144F2205D8",
                "D43D87A6-A28F-4B86-9A96-67AF3E6122D2",
                "8D9BDFA1-C58E-4808-B9E5-7D836EDE24C3",
                "4936767A-B552-4AFF-A6AA-85A98A7A3273",
                "39764E31-F2EB-40B5-88A8-8FBF87CB66F5",
                "2CC6669E-085D-4B62-9BC5-A0379EC65CBE",
                "A0C228BD-4A49-4FCE-BC4D-A72F7B8DDB11",
                "12184E41-B84D-4C2F-9251-CB0F8E8D7DDB",
                "46F2F77D-E912-403C-B326-DA39F2628E08",
                "21DB9D0F-946F-4D2E-8300-E167C20074D3",
                "AF06A611-12CE-4C06-B3AD-E2754D12D516",
                "99E32E28-6F92-4A26-ABF1-EE4F56F5BCB6",
                "C0991BAE-1DF2-4D01-AC1C-F525004BF092",
                "0A652FA5-396F-4814-A633-FE0697008586"
            }
        );

        private List<string> ProcessNames = new List<string> 
        (
            new string[]
            {
                "Compras",
                "Recursos Humanos",
                "DSAM"
            }
        );

        private List<Measure> CodeCoverageMeasureLists = new List<Measure> 
        {
            new Measure(){Name = "Coder Coverage", Value = 35, Unit = "%", LastMeasure = new DateTime(2008,03,03), AscendantMeasure = true, LowThresholdValue = 50, HighThresholdValue = 80},
            new Measure(){Name = "Coder Coverage", Value = 62, Unit = "%", LastMeasure = new DateTime(2008,03,10), AscendantMeasure = true, LowThresholdValue = 50, HighThresholdValue = 80},
            new Measure(){Name = "Coder Coverage", Value = 34, Unit = "%", LastMeasure = new DateTime(2008,02,04), AscendantMeasure = true, LowThresholdValue = 50, HighThresholdValue = 80},
            new Measure(){Name = "Coder Coverage", Value = 12, Unit = "%", LastMeasure = new DateTime(2008,02,29), AscendantMeasure = true, LowThresholdValue = 50, HighThresholdValue = 80},
            new Measure(){Name = "Coder Coverage", Value = 78, Unit = "%", LastMeasure = new DateTime(2008,02,18), AscendantMeasure = true, LowThresholdValue = 50, HighThresholdValue = 80},
            new Measure(){Name = "Coder Coverage", Value = 85, Unit = "%", LastMeasure = new DateTime(2008,03,05), AscendantMeasure = true, LowThresholdValue = 50, HighThresholdValue = 80},
            new Measure(){Name = "Coder Coverage", Value = 22, Unit = "%", LastMeasure = new DateTime(2008,01,03), AscendantMeasure = true, LowThresholdValue = 50, HighThresholdValue = 80},
            new Measure(){Name = "Coder Coverage", Value = 10, Unit = "%", LastMeasure = new DateTime(2008,02,22), AscendantMeasure = true, LowThresholdValue = 50, HighThresholdValue = 80},
            new Measure(){Name = "Coder Coverage", Value = 15, Unit = "%", LastMeasure = new DateTime(2008,02,15), AscendantMeasure = true, LowThresholdValue = 50, HighThresholdValue = 80},
            new Measure(){Name = "Coder Coverage", Value = 44, Unit = "%", LastMeasure = new DateTime(2008,02,27), AscendantMeasure = true, LowThresholdValue = 50, HighThresholdValue = 80},
            new Measure(){Name = "Coder Coverage", Value = 88, Unit = "%", LastMeasure = new DateTime(2008,03,10), AscendantMeasure = true, LowThresholdValue = 50, HighThresholdValue = 80},
            new Measure(){Name = "Coder Coverage", Value = 95, Unit = "%", LastMeasure = new DateTime(2008,02,18), AscendantMeasure = true, LowThresholdValue = 50, HighThresholdValue = 80},
            new Measure(){Name = "Coder Coverage", Value = 17, Unit = "%", LastMeasure = new DateTime(2008,03,12), AscendantMeasure = true, LowThresholdValue = 50, HighThresholdValue = 80},
            new Measure(){Name = "Coder Coverage", Value = 62, Unit = "%", LastMeasure = new DateTime(2008,02,29), AscendantMeasure = true, LowThresholdValue = 50, HighThresholdValue = 80},
            new Measure(){Name = "Coder Coverage", Value = 54, Unit = "%", LastMeasure = new DateTime(2008,02,28), AscendantMeasure = true, LowThresholdValue = 50, HighThresholdValue = 80},
            new Measure(){Name = "Coder Coverage", Value = 47, Unit = "%", LastMeasure = new DateTime(2008,03,04), AscendantMeasure = true, LowThresholdValue = 50, HighThresholdValue = 80},
            new Measure(){Name = "Coder Coverage", Value = 100, Unit = "%", LastMeasure = new DateTime(2008,01,03), AscendantMeasure = true, LowThresholdValue = 50, HighThresholdValue = 80},
            new Measure(){Name = "Coder Coverage", Value = 62, Unit = "%", LastMeasure = new DateTime(2008,02,27), AscendantMeasure = true, LowThresholdValue = 50, HighThresholdValue = 80},
            new Measure(){Name = "Coder Coverage", Value = 89, Unit = "%", LastMeasure = new DateTime(2008,03,03), AscendantMeasure = true, LowThresholdValue = 50, HighThresholdValue = 80},
            new Measure(){Name = "Coder Coverage", Value = 76, Unit = "%", LastMeasure = new DateTime(2008,03,10), AscendantMeasure = true, LowThresholdValue = 50, HighThresholdValue = 80},
            new Measure(){Name = "Coder Coverage", Value = 88, Unit = "%", LastMeasure = new DateTime(2008,03,03), AscendantMeasure = true, LowThresholdValue = 50, HighThresholdValue = 80},
            new Measure(){Name = "Coder Coverage", Value = 76, Unit = "%", LastMeasure = new DateTime(2008,02,22), AscendantMeasure = true, LowThresholdValue = 50, HighThresholdValue = 80},
            new Measure(){Name = "Coder Coverage", Value = 92, Unit = "%", LastMeasure = new DateTime(2008,02,14), AscendantMeasure = true, LowThresholdValue = 50, HighThresholdValue = 80},
            new Measure(){Name = "Coder Coverage", Value = 90, Unit = "%", LastMeasure = new DateTime(2008,03,11), AscendantMeasure = true, LowThresholdValue = 50, HighThresholdValue = 80},
            new Measure(){Name = "Coder Coverage", Value = 12, Unit = "%", LastMeasure = new DateTime(2008,03,12), AscendantMeasure = true, LowThresholdValue = 50, HighThresholdValue = 80}
        };

        private List<Measure> CodeAnalisysMeasureLists = new List<Measure>
        {
            new Measure(){Name = "Code Analysis", Value = 60, Unit = "Warnings", LastMeasure = new DateTime(2008,03,03), AscendantMeasure = false, LowThresholdValue = 10, HighThresholdValue = 30},
            new Measure(){Name = "Code Analysis", Value = 12, Unit = "Warnings", LastMeasure = new DateTime(2008,03,10), AscendantMeasure = false, LowThresholdValue = 10, HighThresholdValue = 30},
            new Measure(){Name = "Code Analysis", Value = 117, Unit = "Warnings", LastMeasure = new DateTime(2008,02,04), AscendantMeasure = false, LowThresholdValue = 10, HighThresholdValue = 30},
            new Measure(){Name = "Code Analysis", Value = 20, Unit = "Warnings", LastMeasure = new DateTime(2008,02,29), AscendantMeasure = false, LowThresholdValue = 10, HighThresholdValue = 30},
            new Measure(){Name = "Code Analysis", Value = 3, Unit = "Warnings", LastMeasure = new DateTime(2008,02,18), AscendantMeasure = false, LowThresholdValue = 10, HighThresholdValue = 30},
            new Measure(){Name = "Code Analysis", Value = 6, Unit = "Warnings", LastMeasure = new DateTime(2008,03,05), AscendantMeasure = false, LowThresholdValue = 10, HighThresholdValue = 30},
            new Measure(){Name = "Code Analysis", Value = 15, Unit = "Warnings", LastMeasure = new DateTime(2008,01,03), AscendantMeasure = false, LowThresholdValue = 10, HighThresholdValue = 30},
            new Measure(){Name = "Code Analysis", Value = 17, Unit = "Warnings", LastMeasure = new DateTime(2008,02,22), AscendantMeasure = false, LowThresholdValue = 10, HighThresholdValue = 30},
            new Measure(){Name = "Code Analysis", Value = 150, Unit = "Warnings", LastMeasure = new DateTime(2008,02,15), AscendantMeasure = false, LowThresholdValue = 10, HighThresholdValue = 30},
            new Measure(){Name = "Code Analysis", Value = 0, Unit = "Warnings", LastMeasure = new DateTime(2008,02,27), AscendantMeasure = false, LowThresholdValue = 10, HighThresholdValue = 30},
            new Measure(){Name = "Code Analysis", Value = 4, Unit = "Warnings", LastMeasure = new DateTime(2008,03,10), AscendantMeasure = false, LowThresholdValue = 10, HighThresholdValue = 30},
            new Measure(){Name = "Code Analysis", Value = 20, Unit = "Warnings", LastMeasure = new DateTime(2008,02,18), AscendantMeasure = false, LowThresholdValue = 10, HighThresholdValue = 30},
            new Measure(){Name = "Code Analysis", Value = 40, Unit = "Warnings", LastMeasure = new DateTime(2008,03,12), AscendantMeasure = false, LowThresholdValue = 10, HighThresholdValue = 30},
            new Measure(){Name = "Code Analysis", Value = 200, Unit = "Warnings", LastMeasure = new DateTime(2008,02,29), AscendantMeasure = false, LowThresholdValue = 10, HighThresholdValue = 30},
            new Measure(){Name = "Code Analysis", Value = 25, Unit = "Warnings", LastMeasure = new DateTime(2008,02,28), AscendantMeasure = false, LowThresholdValue = 10, HighThresholdValue = 30},
            new Measure(){Name = "Code Analysis", Value = 10, Unit = "Warnings", LastMeasure = new DateTime(2008,03,04), AscendantMeasure = false, LowThresholdValue = 10, HighThresholdValue = 30},
            new Measure(){Name = "Code Analysis", Value = 5, Unit = "Warnings", LastMeasure = new DateTime(2008,01,03), AscendantMeasure = false, LowThresholdValue = 10, HighThresholdValue = 30},
            new Measure(){Name = "Code Analysis", Value = 20, Unit = "Warnings", LastMeasure = new DateTime(2008,02,27), AscendantMeasure = false, LowThresholdValue = 10, HighThresholdValue = 30},
            new Measure(){Name = "Code Analysis", Value = 12, Unit = "Warnings", LastMeasure = new DateTime(2008,03,03), AscendantMeasure = false, LowThresholdValue = 10, HighThresholdValue = 30},
            new Measure(){Name = "Code Analysis", Value = 17, Unit = "Warnings", LastMeasure = new DateTime(2008,03,10), AscendantMeasure = false, LowThresholdValue = 10, HighThresholdValue = 30},
            new Measure(){Name = "Code Analysis", Value = 22, Unit = "Warnings", LastMeasure = new DateTime(2008,03,03), AscendantMeasure = false, LowThresholdValue = 10, HighThresholdValue = 30},
            new Measure(){Name = "Code Analysis", Value = 3, Unit = "Warnings", LastMeasure = new DateTime(2008,02,22) , AscendantMeasure = false, LowThresholdValue = 10, HighThresholdValue = 30},
            new Measure(){Name = "Code Analysis", Value = 11, Unit = "Warnings", LastMeasure = new DateTime(2008,02,14), AscendantMeasure = false, LowThresholdValue = 10, HighThresholdValue = 30},
            new Measure(){Name = "Code Analysis", Value = 140, Unit = "Warnings", LastMeasure = new DateTime(2008,03,11), AscendantMeasure = false, LowThresholdValue = 10, HighThresholdValue = 30},
            new Measure(){Name = "Code Analysis", Value = 2, Unit = "Warnings", LastMeasure = new DateTime(2008,03,12), AscendantMeasure = false, LowThresholdValue = 10, HighThresholdValue = 30}
        };

        public MockMeasuresService()
        {
            this.Measures = new Dictionary<string, Dictionary<string, List<Measure>>>();

            for (int i = 0; i < ProjectUris.Count; i++)
            {
                Dictionary<string, List<Measure>> MeasuresByProject = new Dictionary<string, List<Measure>>();

                //ProcessName: DSAM
                MeasuresByProject.Add(
                    ProcessNames[2],

                    new List<Measure>(new Measure[]
                    {
                        CodeCoverageMeasureLists[i],
                        CodeAnalisysMeasureLists[i],
                    })
                );

                //ProcessName: Compras
                MeasuresByProject.Add(
                    ProcessNames[0],

                    new List<Measure>(new Measure[]
                    {
                        CodeCoverageMeasureLists[(i+5) % 25]
                    })
                );
                this.Measures.Add(ProjectUris[i].ToLower(CultureInfo.CurrentCulture), MeasuresByProject);
            }
        }

        #region IMeasureService Members

        public Measure[] GetMeasuresByProcessName(Guid projectId, string processName)
        {
            Measure[] returnValue = null;

            if (this.Measures.ContainsKey(projectId.ToString().ToLower(CultureInfo.CurrentCulture)))
            {
                Dictionary<string, List<Measure>> MeasuresByProject = this.Measures[projectId.ToString().ToLower(CultureInfo.CurrentCulture)];

                if (MeasuresByProject.ContainsKey(processName))
                {
                    if (MeasuresByProject[processName] != null)
                    {
                        returnValue = MeasuresByProject[processName].ToArray();
                    }
                }
            }
            
            return returnValue;
        }

        #endregion
    }
}
